package com.rapig.mail;

import java.awt.SystemTray;

import javax.swing.SwingUtilities;
import javax.swing.UIManager;

import com.rapig.mail.bean.MailAccount;
import com.rapig.mail.biz.ConfigBIZ;
import com.rapig.mail.biz.MailBIZ;
import com.rapig.mail.biz.MailTask;
import com.rapig.mail.biz.TrayBIZ;

public class MailTray {
	private static Thread tHash = null;

	public static void main(String[] args) {
		String json = ConfigBIZ.read("account.rpg");
		System.out.println(json);
		MailBIZ.accounts = MailAccount.fromJsonList(json);

		if (tHash == null) {
			tHash = new Thread(new MailTask());
		}
		tHash.start();

		try {
			String look = "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
			look = "javax.swing.plaf.metal.MetalLookAndFeel";
			UIManager.setLookAndFeel(look);
		} catch (Exception ex) {
		}
		/* Turn off metal's use of bold fonts */
		UIManager.put("swing.boldMetal", Boolean.FALSE);
		// Schedule a job for the event-dispatching thread:
		// adding TrayIcon.

		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				createAndShowGUI();
			}
		});

	}

	private static void createAndShowGUI() {
		// Check the SystemTray support
		if (!SystemTray.isSupported()) {
			System.out.println("SystemTray is not supported");
			return;
		}
		TrayBIZ.initTray();
	}

}
